home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip
/
MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf
/
Programming
/
PASCAL_TUTES
/
tute1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-06-24
|
7KB
|
146 lines
{
Tutorial One
Write Lines? I thought that was a school thing...
Don't adjust your monitor! The curly brackets indicate comments
for pascal programs. In other words, this whole article is source
code that you can compile into an executable program. It saves
on the re-typing and means no separate source files! All the
extraneous remarks will be in these curly brackets and in this
colour (i.e. the guts of the tutorial), while the program lines
themselves will be coloured like this...
This could be a program line but it isn't;
You'll note that all curly brackets are part of the program.
That's because they're all comments!
If this isn't clear then go and have a cup of coffee, dip your
head in a bucket of sour milk, say "I love pickled herring" three
times, then come back and try again!
Alternatively, run the program RemCom (found in the
example_programs drawer) which will remove all these comments from
the file, just leaving the source code. Magic!
What's more important? Careful study of a subject until
understanding brings the confidence to apply your knowledge, or
suck it and see, the time-honoured approach to computer technology?
We'll use mostly the latter as we travel down the Pascal highway
towards enlightenment. It's cruel and dirty, and produces
programming cowboys, but it's less likely to lead to early baldness
and debilitating halitosis.
I know you're bursting to write your first Pascal program, so we'll
commence with a simple example program. If you want to re-write
just the program lines you'll need a text editor, or word processor
capable of saving in ASCII format. Also, a Pascal compiler would
be handy! If you don't have the compiler I've included the
executables along with these tutorials in a drawer marked
"Example_Programs". You'll need to open a CLI window to run them.
Here is our first program...
}
Program MDTute1 (output);
{
^ ^ ^ ^
| | | |
| | | |__
Semicolon: The end of every line
| | |
in a Pascal program is identified
| | |
by a semicolon. Amazing.
| | |
| | |__
Output: Tell the compiler that we will be
| |
requiring output from this program. Note
| |
the round brackets!
| |
| |__
Identifier: This is the name of our program. It
|
must begin with a letter, then it may have any
|
number of digits or letters. Try U682Higgle!
|
|__
Program: This tells your compiler that the textfile being
examined is in fact a program. The first word of every
Pascal source file is Program. This is a reserved word in
Pascal, so you can't use it as a variable name or for
scraping off the black bits from your burnt toast.
}
{ A brilliant program to output a message to the screen
Author : A N Peck
Date : 15 June 1994 }
{
This is a program comment. While it's not necessary to write
anything, it is good programming practice to write here details of
the program's function, author and date of inception. Even more
useful information can be kept here in an opening comment, and
we'll discuss that when we get into functions and procedures
(Yikes).
}
Begin
{
Begin: This is a really tricky concept. It means that this is the
start of the program...
}
Writeln ('It''s a long way from Tipperary!');
{
^ ^^ ^ ^^
| || | ||
| || | ||__
Closing Bracket!
| || | |
| || | |__
Closing apostrophe
| || |
| || |__
I did mean to write this second apostrophe!
| ||
Honest! Actually because the writeln statement
| ||
requires apostrophes, whenever we need a real
| ||
one, we need to write it twice. Cosmic.
| ||
| ||__
Opening apostrophe
| |
| |__
Opening bracket
|
|__
This weird word is another reserved word, and it tells the
compiler that we want to output something (usually to the
screen). The Writeln command differs from Write in that
writeln, after writing the statement in the brackets, will
then enter a carriage return so that the next line will be
on the next line (eh?)
Example: Writeln('Four stores and ');
Writeln('seven shops ago...');
produces the output
Four stores and
seven shops ago....
whereas
Write('Four stores and ');
Writeln('seven shops ago...');
produces the output
Four stores and seven shops ago....
}
Writeln;
{
^
|
|__
This makes a blank line!
}
End.
{
Another brutally torturous concept. This is the end of the
program. Note the fullstop!
Wasn't that exciting! Before going on to the next tutorial,
why not play around with this code to produce your own program?
Try centering the text, and writing multiple and blank lines.
We'll talk of this text formatting again.
----------------------END OF TUTE1.PAS----------------------
}